package cn.wangkai.peanut.db.iface;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

import cn.wangkai.peanut.db.WKDbException;
import cn.wangkai.peanut.db.mod.GeneratedKey;
import cn.wangkai.peanut.db.util.ManagerException;
import cn.wangkai.peanut.db.util.PageModel;
import cn.wangkai.peanut.db.util.SQLUtil;

public interface IDbFactory {

	/**
	 * 插入数据，得到自动获取的主键
	 * @param sql SQL语句
	 * @param pmdKnownBroken
	 * @param params
	 * @return
	 * @throws SQLException
	 */
	public GeneratedKey add(IMyDb db,String sql, Object... params) throws WKDbException, SQLException;


	/**
	 * 更新方法
	 * @param sql
	 * @param params
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 * @throws Exception
	 */
	public int execute(IMyDb db,String sql, Object... params) throws SQLException, WKDbException;

	/**  
	* 执行批量sql语句  
	* @param sql sql语句  
	* @param params 二维参数数组  
	* @return 受影响的行数的数
	* @throws SQLException 
	 * @throws WKDbException 
	*/  
	public int[] batchexecute(IMyDb db,String sql, Object[]... params) throws SQLException, WKDbException ;

	public <T> List<T>  query(IMyDb db, Class<?> module,SQLUtil sqlUtil) throws SQLException, WKDbException;
	
	/**
	 * 得到列表数据
	 * @param sql
	 * @param module
	 * @param param
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public <T> List<T>  query(IMyDb db,String sql, Class<?> module, List<Object> params) throws SQLException, WKDbException;

	
	
	/**
	 * 执行查询方法(使用)
	 * @param <T>
	 * @param sql
	 * @param module
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public <T> List<T> query(IMyDb db,String sql, Class<?> module, Object... params) throws SQLException, WKDbException ;

	public <T> T getOne(IMyDb db, Class<?> module,SQLUtil sqlUtil) throws SQLException, WKDbException ;
	
	/**
	 * 查询单个数据
	 * @param sql
	 * @param module
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public <T> T getOne(IMyDb db,String sql, Class<?> module,Object... params) throws SQLException, WKDbException ;
	
	public BigDecimal getcount(IMyDb db,SQLUtil sqlUtil) throws SQLException, WKDbException;
	/**
	 * 
	 * @param sql
	 * @param params
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public BigDecimal getcount(IMyDb db,String sql,List<Object> params) throws SQLException, WKDbException;
	/**
	 * 
	 * @param sql
	 * @param param
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public BigDecimal getcount(IMyDb db,String sql, Object... param) throws SQLException, WKDbException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param module
	 * @param selects
	 * @param sqlUtil
	 * @param pagesize
	 * @param pagenum
	 * @param Orders
	 * @param Descs
	 * @return
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public <T> PageModel<T> get_cutpage(IMyDb db,Class<?> module,String selects,SQLUtil sqlUtil,int pagesize,int pagenum,String[] Orders,Boolean[] Descs) throws SQLException, WKDbException;

	/**
	 * 
	 * @param db.getConnection()
	 * @param module
	 * @param selects
	 * @param sqlUtil
	 * @param pagesize
	 * @param pagenum
	 * @param Orders
	 * @param Descs
	 * @return
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public <T> PageModel<T> get_cutpage(IMyDb db,Class<?> module,String selects,SQLUtil sqlUtil,int pagesize,int pagenum,String Orders,Boolean Descs) throws SQLException, WKDbException;
	
	/**
	 * 
	 *	一、MySQL
	 *		driverClass：com.mysql.jdbc.Driver
	 *		jdbcUrl：jdbc:mysql://192.168.0.1:3306/yourDBName 硬编码（不建议）
     *		Class.forName("com.mysql.jdbc.Driver", true, Thread.currentThread().getContextClassLoader());
     *		db.getConnection()=DriverManager.getConnection("jdbc:mysql://192.168.0.1:3306/yourDBName?user=userName&password=123");
	 *	二、Oracle
	 *		driverClass：oracle.jdbc.driver.OracleDriver
	 *		jdbcUrl：jdbc:oracle:thin:@192.168.0.1:1521:yourDBName
	 *	三、SQL Server
	 *		driverClass：com.microsoft.sqlserver.jdbc.SQLServerDriver 005版本及以后）
	 *					com.microsoft.jdbc.sqlserver.SQLServerDriver 000版本
	 *		jdbcUrl：jdbc:sqlserver://192.168.0.1:1433;databasename=yourDBName
	 *	四、Sybase
	 *		driverClass
	 *		jdbcUrl??
	 *	五、DB2
	 *		1、db2java.zip
	 *			driverClass：COM.ibm.db2.jdbc.net.DB2Driver
	 *			jdbcUrl：jdbc:db2://ip:6789/DBNAME
	 *		2、db2jcc.jar
	 *			driverClass：com.ibm.db2.jcc.DB2Driver
	 *			jdbcUrl：jdbc:db2://ip:port/DBNAME
	 *	 六、Informix
	 *		driverClass
	 *		jdbcUrl
	 *	七、PostgreSQL
	 *		driverClass
	 *		jdbcUrl
	 * @param <T>
	 * @param module
	 * @param selects
	 * @param sql
	 * @param pagesize
	 * @param pagenum
	 * @param params
	 * @param Orders
	 * @param Descs
	 * @return
	 * @throws SQLException 
	 * @throws WKDbException 
	 */
	public <T> PageModel<T> get_cutpage(IMyDb db,Class<?> module,String selects,String sql,int pagesize,int pagenum,List<Object> params,List<String> Orders,List<Boolean> Descs) throws SQLException, WKDbException;
	/**
	 * 
	 * @param db.getConnection()
	 * @param module
	 * @param selects
	 * @param sql
	 * @param pagesize
	 * @param pagenum
	 * @param params
	 * @param Orders
	 * @param Descs
	 * @return
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public <T> PageModel<T> get_cutpage(IMyDb db,Class<?> module,String selects,String sql,
			int pagesize,int pagenum,List<Object> params,String Orders,Boolean Descs) throws SQLException, WKDbException;

	/**
	 * 
	 * @param db.getConnection()
	 * @param module
	 * @param selects
	 * @param sql
	 * @param pagesize
	 * @param pagenum
	 * @param params
	 * @param Orders
	 * @param Descs
	 * @return
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public <T> PageModel<T> get_cutpage(IMyDb db,Class<?> module,String selects,String sql,
			int pagesize,int pagenum,List<Object> params,String[] Orders,Boolean[] Descs) throws SQLException, WKDbException;
	/*******************************************以下对象相关****************************************/
	/**
	 * 
	 * @param obj
	 * @param keyword
	 * @param keywordauto
	 * @return
	 * @throws ManagerException 
	 * @throws WKDbException 
	 * @throws Exception
	 */
	public int add(IMyDb db,Object obj,boolean keywordauto,String... keyword) throws SQLException, ManagerException, WKDbException ;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	public int addselect(IMyDb db,Object obj)throws SQLException, WKDbException, ManagerException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws ManagerException
	 * @throws WKDbException
	 * @throws SQLException
	 */
	public GeneratedKey addselectgetID(IMyDb db,Object obj) throws ManagerException, WKDbException, SQLException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws ManagerException
	 * @throws WKDbException
	 * @throws SQLException
	 */
	public GeneratedKey add(IMyDb db,Object obj) throws ManagerException, WKDbException, SQLException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws WKDbException
	 * @throws SQLException
	 * @throws ManagerException
	 */
	public Long addgetLongID(IMyDb db,Object obj) throws WKDbException, SQLException, ManagerException;

	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws WKDbException
	 * @throws SQLException
	 * @throws ManagerException
	 */
	public Integer addgetIntegerID(IMyDb db,Object obj) throws WKDbException, SQLException, ManagerException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @return
	 * @throws WKDbException
	 * @throws SQLException
	 * @throws ManagerException
	 */
	public BigDecimal addgetBigDecimalID(IMyDb db,Object obj) throws WKDbException, SQLException, ManagerException;

	/**
	 * 
	 * @param obj
	 * @param keyword
	 * @return
	 * @throws ManagerException 
	 * @throws WKDbException 
	 * @throws Exception
	 */
	public int update(IMyDb db,Object obj,String... keywords) throws ManagerException, WKDbException, SQLException;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @param keywords
	 * @return
	 * @throws ManagerException
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public int delobj(IMyDb db,Object obj,String... keywords) throws ManagerException, SQLException, WKDbException ;
	
	/**
	 * 
	 * @param db.getConnection()
	 * @param obj
	 * @param sql
	 * @return
	 * @throws ManagerException
	 * @throws SQLException
	 * @throws WKDbException 
	 */
	public int del(IMyDb db,Object obj,String sql) throws ManagerException, SQLException, WKDbException ;

}
